#pragma once

#include "Framework/CommonHead.h"
#include "Widgets/RectangleWidget.h"
#include "Widgets/Mouse/MouseWidget.h"
#include "ScrollBar.m.h"

/*
    Imagine you have a very long page show in a slide window

    ContentTotalLength= Page height
    SlideWindowLength = slide window height
    CurrentPercent    =  current slide window top position / ( Page height- slide window height)
*/
RCLASS()
class WHENGINE_API RScrollBar: public RRectangleWidget
{
    ROBJECT
public:
    RScrollBar();

    void SetContentTotalLength(float InLength,bool RecalculatePercent=false);

    void SetSlideWindowLength(float InLength);

    void SetCurrentPercent(float Position); 

    float GetCurrentPercent() const { return Percent; }


    TDelegate<void,float /*percent */ > OnPercentChanged;
private:
    bool ShouldBeVisible()
    {
        return SlideWindowLength < ContentTotalLength;
    }

    float SlideWindowLength=10;
    float ContentTotalLength=100;
    float Percent=0;


    
    // void UpdateSliderPosition();
    // void UpdateSliderSize();
    TWeakObjectPtr<RRectangleWidget> SlideArea;
    TWeakObjectPtr<RRectangleWidget> Slider;

    bool OnTopButtonClicked(const SMouseButtonEvent&);
    bool OnBottomButtonClicked(const SMouseButtonEvent&);
    void OnDragging(const SVec2& TotalMouseDistance);

    TWeakObjectPtr<RMouseWidget> SlideAreaMouse;
    bool OnBlankAreaClick(const SMouseButtonEvent&);

};